<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业logo上传管理</title>
    <style>
        #uploadDiv {
            color: #666666;
            height: 500px;
            width: 400px;
            /*text-align:center;*/
            font-size: 18px;
            margin:0 auto;
        }

    </style>
</head>
<body>

<div id="uploadDiv">
    <h1>管理员图片上传</h1>
    <div class="form-group"> <input type="file" id="pic"></div>
    <div class="form-group"> <input id="hiddenUrl" type="hidden" value=""></div>
    <!--<div class="form-group"> <input type="button" id="uploadButton" value="上传图片" onclick="uploadPic()"></div>-->
    <div class="form-group">
        <button id="unload" class="btn btn-primary btn-block" type="submit" >上 &nbsp;传
        </button>
    </div>
    <div class="form-group">
        <button id="commit" class="btn btn-primary btn-block" type="submit">提 &nbsp;交
        </button>
    </div>
   <!--<form id="uploadPic" enctype="multipart/form-data" method="post">
        <input type="file" id="pic">
        <input id="hiddenUrl" type="hidden" value="">
        <input type="button" id="uploadButton" value="上传图片" onclick="uploadPic()">
        <input type="submit" onclick="savePic()">
    </form>-->

</div>
<script type="text/javascript" src="js/jquery-1.10.2.min.js">
</script>
<script type="text/javascript">
    $("#unload").click(function () {

        var pic = (document.getElementById("pic").files[0]);
        if (pic == null) {
            alert("uploadPic if启动");
        } else {
            var formData = new FormData();
            formData.append("pic", pic);
            //debugger
            $.ajax({
                url: "http://47.111.69.237:8092/uploadPic/",
                type: "POST",
                data: formData,
                dataType: "json",
                cache: false,
                processData: false,
                contentType: false,
                async: false,
                success: function (res1) {
                    // alert(res1.data);
                    alert("恭喜，上传成功！");
                    $("#hiddenUrl").attr('value', res1.data);
                },
            })
        }
    })

    $("#commit").click(function ()  {
        var picData = document.getElementById("hiddenUrl").value;
        if (picData == null) {
        } else {
            //var url = document.getElementById("hiddenUrl").value;
            $.ajax({
                url: "http://47.111.69.237:8092/enterprice/updateLogo/",
                type: "POST",
                data: {"url": picData, "id": 1},
                dataType: "json",
                async: false,
                success: function (result) {
                    if (result.success){
                        alert("恭喜，提交成功！");
                        window.location.href = "user.html";
                    } else{
                        alert("提交失败")
                        window.location.href = "root.html";
                    }
                }
            })
        }
    })
</script>
</body>
</html>